/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.xgb.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.xgb.entity.XgbBoardDown;
import com.zcm.modules.xgb.service.XgbBoardDownService;

/**
 * xgbBoardDown
 * @author www
 * @version 2018-10-07
 */
@Controller
@RequestMapping(value = "${adminPath}/xgb/xgbBoardDown")
public class XgbBoardDownController extends BaseController {

	@Autowired
	private XgbBoardDownService xgbBoardDownService;
	
	@ModelAttribute
	public XgbBoardDown get(@RequestParam(required=false) String id) {
		XgbBoardDown entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = xgbBoardDownService.get(id);
		}
		if (entity == null){
			entity = new XgbBoardDown();
		}
		return entity;
	}
	
	@RequiresPermissions("xgb:xgbBoardDown:view")
	@RequestMapping(value = {"list", ""})
	public String list(XgbBoardDown xgbBoardDown, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<XgbBoardDown> page = xgbBoardDownService.findPage(new Page<XgbBoardDown>(request, response), xgbBoardDown);
		model.addAttribute("page", page);
		return "modules/xgb/xgbBoardDownList";
	}

	@RequiresPermissions("xgb:xgbBoardDown:view")
	@RequestMapping(value = "form")
	public String form(XgbBoardDown xgbBoardDown, Model model) {
		model.addAttribute("xgbBoardDown", xgbBoardDown);
		return "modules/xgb/xgbBoardDownForm";
	}

	@RequiresPermissions("xgb:xgbBoardDown:edit")
	@RequestMapping(value = "save")
	public String save(XgbBoardDown xgbBoardDown, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, xgbBoardDown)){
			return form(xgbBoardDown, model);
		}
		xgbBoardDownService.save(xgbBoardDown);
		addMessage(redirectAttributes, "保存XgbBoardDown成功");
		return "redirect:"+Global.getAdminPath()+"/xgb/xgbBoardDown/?repage";
	}
	
	@RequiresPermissions("xgb:xgbBoardDown:edit")
	@RequestMapping(value = "delete")
	public String delete(XgbBoardDown xgbBoardDown, RedirectAttributes redirectAttributes) {
		xgbBoardDownService.delete(xgbBoardDown);
		addMessage(redirectAttributes, "删除XgbBordDown成功");
		return "redirect:"+Global.getAdminPath()+"/xgb/xgbBoardDown/?repage";
	}

}